<include file="Public:header" />
<script type="text/javascript" src="{$Think.TP_CKFINDER}/ckfinder.js"></script>
<script type="text/javascript"> 
var divId=10;
var maxPic='{$maxPic}';
function BrowseServer(obj){
	var finder = new CKFinder(); 
	finder.basePath = '{$Think.TP_CKFINDER}/'; 
	finder.startupPath = 'Images:/News/';
	finder.selectActionFunction = SetFileField;
	finder.selectThumbnailActionFunction = ShowThumbnails;
	finder.popup();
}
function SetFileField(fileUrl,data){
	var sFileName = this.getSelectedFile().name;	
	setView(fileUrl,data,sFileName);
}
function ShowThumbnails(fileUrl,data)
{
	var sFileName = this.getSelectedFile().name;
	setView(fileUrl,data,sFileName);
	return false;
}
function setView(fileUrl,data,sFileName){
	var arr = new Array();
	var val = $("#pic").val();
	if(val!=""){
		var tmp = val.split(",");
		if(tmp.length>=maxPic){
			alert("最多上传图片" + maxPic + "张图片!");
			return false;
		}
		for(var i=0,j=0;i<tmp.length;i++){
			if(tmp[i]==fileUrl){
				alert("您选择的图片已存在!");
				return false;
			}
			if(tmp[i]!=""){
			    arr[j]=tmp[i];
				j++;
			}
		}	
		arr.push(fileUrl);
		var arr = arr.join(",");
		$("#pic").val(arr);
	}else{
		$("#pic").val(fileUrl);
	}
	var thumbid = "thumb"+divId;
	var inputid = "input"+divId;
	var tpl='<div class="thumb" id="'+thumbid+'">' +
				'<img class="thumbimg" src="' + fileUrl + '" height="150"/>' +
				'<div class="caption">' +
					'<input type="hidden" id="' + inputid + '" value="'+ fileUrl +'">' + 
					'<a href="' + data["fileUrl"] + '" target="_blank" class="fl">' + sFileName + '</a> ' +
					'<div onclick="delPic(\'' + thumbid + '\', \'' + inputid + '\')" class="ui-state-default ui-corner-all fl noboder" style="border:none;"><span class="ui-icon ui-icon-circle-minus fl"></span><font class="fl">删除<font></div>' +
				'</div>' +
			'</div>';			
	$("#thumbnails").append(tpl);
	$('#preview').css("display","");
	$("#prompt").css("display","none");
	divId++;
}
function delPic(divid,inputid){
	var val = $("#pic").val();
	var arr = val.split(",");
	var input = $("#"+inputid).val();
	arr.splice($.inArray(input,arr),1);
	var arr = arr.join(",");
	$("#pic").val(arr);
	$("#"+divid).remove();
	if(arr=="")$("#prompt").css("display",""); 
}
$(function(){
    $('#addPart').validate({
        errorPlacement: function(error, element){
            $(element).next('.field_notice').hide();
            $(element).after(error);
        },
        success:function(label){
            label.addClass('right').text('OK!');
        },
        rules : {
            title : {
                required : true
            },
            desc : {
                required : true
            },		
            cid : {
                required : true
            },										
        },
        messages : {
            title : {
                required : '不能为空'
            },
			desc : {
                required : '不能为空'
            },
			cid : {
                required : '请选择'
            },			
        }	
    });
});
</script>
<style>
body{font-size:12px;}
.sminput{width:30px; text-align:center;}
td a{ margin:0 5px;}
tr{ height:40px;}
.red{ color:#F00}
.fl{float:left;}
</style>
<div id="content">
	<div id="main">
    	<div class="pad20">
        	<if condition="$myself neq 1">
                <include file="Public:navig" />
                <div>
                    <p style="text-align:right;"><input onclick="selflo('{$lasturl}')" class="button" type="submit" value="返回上一级" /></p>
                </div>
            </if>
			<div id="tabs">            
                <ul>
               		 <li><a href="#tabs-1">{$tabs}</a></li>
                </ul>               
                
                <div id="tabs-1">
                <form id="addPart" method="post" action="__APP__/Do/{$act}/">
                <input type="hidden" name="model" value="{$model}" />
                <input type="hidden" name="act" value="{$act}" />
                <input type="hidden" name="callback" value="{$callback}" />       
                <input type="hidden" name="id" value="{$res['id']}" />                
                <table border="0" cellpadding="0" cellspacing="0">
                    <tr>   
                    	<td>标题：</td>
                    	<td style="padding:8px 0;">
                    <textarea name="title" class="fl" style="height:50px;">{$res['title']}</textarea><span class="red fl">*</span>必填</label>
                    </td>
                    <tr>   
                    	<td>描述：</td>
                    	<td style="padding:8px 0;">
                    <textarea name="desc" class="fl" style="height:50px;">{$res['desc']}</textarea><span class="red fl">*</span>必填</label>
                    </td>
                    <tr>   
                        <td>所属分类：</td>
                        <td style="padding:8px 0;">
                            <select id="cid" name="cid" class="input">
                                <option value="">请选择...</option>
                                {$cate}
                            </select>
                        </td>
                    </tr>
                    <tr>   
                        <td>封面图片：</td>
                        <td>
                        <input type="hidden" id="pic" name="pic" value="{$res['ppic']}"/>
                        <input class="button" type="button" name="upimgBtn" id="upimgBtn" onclick="BrowseServer(this);" value="上传图片" />
                        </td>
                    </tr>
                    <tr>
                 		<td>&nbsp;</td>
                    	<td style="padding:10px 0;">
                    	<if condition="empty($res['pic'])">
                            <div id="preview" style="display:none;">
                                <div id="thumbnails"></div>
                            </div>
                            <div id="prompt" style="display:;">
                                <div class="ui-state-default ui-corner-all fl noboder" style="border:none;"><span class="ui-icon ui-icon-alert fl"></span></div>
                                <div class="fl">
                                    请选择封面图片!
                                </div>    
                            </div>  
                         <else />   
							<div id="preview">
                                <div id="thumbnails">
                                <volist name="res['pic']" id="vo" key="k">
                                	<?php
                                    	$e = explode("/",$vo);
                                        $e = end($e);
                                    ?> 	
                                	<div class="thumb" id="thumb{$k}">
                                    	<img class="thumbimg" src="{$vo}" height="150">
                                        <div class="caption">
                                        	<input type="hidden" id="input{$k}" value="{vo.pic}">
                                            	<a href="{$vo}" target="_blank" class="fl">{$e}</a> 
                                                <div onclick="delPic('thumb{$k}', 'input{$k}')" class="ui-state-default ui-corner-all fl noboder" style="border:none;"><span class="ui-icon ui-icon-circle-minus fl"></span><font class="fl">删除<font></font></font></div></div></div>
                                </volist>    
                                </div>
                            </div>
                            <div id="prompt" style="display:none;">
                                <div class="ui-state-default ui-corner-all fl noboder" style="border:none;"><span class="ui-icon ui-icon-alert fl"></span></div>
                                <div class="fl">
                                    请选择封面图片!
                                </div>    
                            </div>                         	
                         </if>       
                    </td>
                 	</tr>
                    <tr>
                    	<td>内容：</td>
                    	<td>{$html}</td>
                    </tr>
                    <tr>
                    	<td colspan="2"><input class="button" type="submit" value="保存" /></td>
                    </tr>
                 </table>
                 </form>
                </div>                                 
			</div>  
        </div>
	</div>
</div>            
                
<include file="Public:footer" />    